package cn.itsource.hrm.config;

import cn.itsource.hrm.constants.MQConstants;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitmqConfig {
    @Value("${site.routingkey}")
    private String routingKey;

    //定义交换机
    @Bean(MQConstants.NAME_EXCHANGE_PAGE_DIRECT)//bean的名字
    public Exchange exchange() {
        //durable(true)持久化，消息队列重启后交换机仍然存在
        return ExchangeBuilder.topicExchange(MQConstants.NAME_EXCHANGE_PAGE_DIRECT).durable(true).build();
    }

    //定义队列
    @Bean(MQConstants.NAME_QUEUE_PAGE_DIRECT)
    public Queue queue(){
        return new Queue(MQConstants.NAME_QUEUE_PAGE_DIRECT);
    }

    //绑定队列到交换机,调用方法方式
    @Bean
    public Binding bindingQueue() {
        return BindingBuilder.bind(queue()).to(exchange()).with(routingKey).noargs();
    }

}
